clear all
program drop _all
set more off
set mem 600m

cd "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\kwan"
use "D:\raw\1930.dta"

keep gq empstat school occ1950 bpl bpld fbpl mbpl statefip county perwt empstatd classwkrd empstatd classwkrd

keep if empstat==1
drop if empstatd==13
drop if classwkrd==29
drop if school==2
keep if occ1950<979

keep if bpld<15000 | bpld==90011 | bpld==90021 | bpld==90022
drop if bpl==200 | fbpl==200 | mbpl==200

replace county = (1000*statefip) + (county/10)

* Arizona
replace county = 4009 if county == 4011

* Louisiana
replace county = 22097 if county == 22039
replace county = 22019 if county == 22011 | county == 22003 | county == 22053

* New Mexico
replace county = 35017 if county == 35023
replace county = 35019 if county == 35011
replace county = 35005 if county == 35025

* Nevada
replace county = 32013 if county == 32027
replace county = 32009 if county == 32021

* Oklahoma
replace county = 40031 if county == 40033

* Oregon
replace county = 41013 if county == 41031 | county == 41017

* Texas
replace county = 48141 if county == 48229 | county == 48109
replace county = 48137 if county == 48385
replace county = 48355 if county == 48273 | county == 42849
replace county = 48061 if county == 48489
replace county = 48427 if county == 48407

* Utah
replace county = 49047 if county == 49009
replace county = 49051 if county == 49013

gen group=1 //low-skill
replace group=2 if occ1950>=0 & occ1950<=99 //high-skill
replace group=2 if occ1950>=300 & occ1950<=390 //high-skill
replace group=2 if occ1950>=400 & occ1950<=490 //high-skill
replace group=2 if occ1950>=500 & occ1950<=595 //high-skill
replace group=2 if occ1950>=600 & occ1950<=690 //high-skill
replace group=2 if occ1950>=500 & occ1950<=595 //high-skill
replace group=. if occ1950>=100 & occ1950<=123 //Drop farmers

drop if group==.

collapse (sum) emp30_native=perwt, by(county group)

reshape wide emp30_native, i(county) j(group)

rename emp30_native1 emp30_native_low
rename emp30_native2 emp30_native_high

save native_emp_by_group_2groups_1930.dta, replace 
